knitr::opts_chunk$set(echo = TRUE)
We import the data and select the variables needed for the analysis.
tmp <- strsplit(FORMULA, "~")[[1]] y.var <- names(unlist(sapply(colnames(CalibrationData), grep, x = tmp[1]))) x.vars <- names(unlist(sapply(colnames(CalibrationData), grep, x = tmp[2]))) if(SUBSET != ""){ calData <- eval(call("subset", x = CalibrationData, subset = parse(text = SUBSET))) }else{ calData <- CalibrationData } calData <- calData[,c(y.var, x.vars)] calData
We will apply the following model.
FORMULA
We now fit (simple) linear model.
fit <- lm(as.formula(FORMULA), data = calData) summary(fit)
We determine the inverse of the fitted model.
ab <- coef(fit) names(ab) <- NULL predFunc <- function(newdata){} body(predFunc) <- substitute({ with(newdata, (eval(y)-a)/b) }, list(y = parse(text = respVar), a = ab[1], b = ab[2]))
We plot the given concentrations against the fitted values.
library(ggplot2) modelPlot <- ggplot(calData, aes_string(x = concVar, y = respVar)) + geom_point() + geom_smooth(method = "lm") + annotate("text", x=-Inf, y = Inf, label = substitute(paste(R^2, " = ", R2, ", adj. ", R^2, " = ", adj.R2), list(R2 = summary(fit)$r.squared, adj.R2 = summary(fit)$adj.r.squared)), vjust=1, hjust=0, size = 5) modelPlot
We compute limit of blank (LOB), limit of detection (LOD) and limit of quantification (LOQ) by inverting the regression fit. We get the LOB by inverting the upper bound of the one-sided 95\% confidence interval at concentration $0$. In caso of the LOD, the upper-bound of the 99.95\% confidence interval at concentration $0$ is inverted. LQQ we define as $3\times\textrm{LOD}$.
LOB <- (confint(fit, parm = 1, level = 0.90)[2]-ab[1])/ab[2] names(LOB) <- "LOB" LOB LOD <- (confint(fit, parm = 1, level = 0.999)[2]-ab[1])/ab[2] names(LOD) <- "LOD" LOD LOQ <- 3*LOD names(LOQ) <- "LOQ" LOQ
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.